package com.atguigu.test01;

import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class test05 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 1; i <= 6; i++) {
            String num = String.valueOf(i);
            new Thread(() -> {
                try {
                    System.out.println(Thread.currentThread().getName()+num+"收拾东西");
                    TimeUnit.SECONDS.sleep(new Random().nextInt(10));
                    System.out.println(num+"离开");
                    countDownLatch.countDown();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            },num+" ").start();
        }
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName()+"锁门");
    }
}
